/******************************************************************************
 *
 * MotionViewer
 * Copyright (C) 2007 Sangyoon Lee, Electronic Visualization Laboratory, 
 * University of Illinois at Chicago
 *
 * This software is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either Version 2.1 of the License, or 
 * (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
 * License for more details.
 * 
 * You should have received a copy of the GNU Lesser Public License along
 * with this software; if not, write to the Free Software Foundation, Inc., 
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * Questions or comments about MotionViewer should be directed to 
 * cavern@evl.uic.edu
 *
 *****************************************************************************/

#ifndef __MOTIONVIEWER_H_
#define __MOTIONVIEWER_H_

#include <CEGUI.h>
#include <ogreplatform.h>
#include "BaseApplication.h"
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#include "../res/resource.h"
#endif

using namespace Ogre;

class ViconVisualizer;
class ViconRTVisualizer;
class ViconVVisualizer;
class MocapVisualizer;
class ViconCharacter;
class ViconSubject;

class MotionViewerApp : public BaseApplication
{
public:
	MotionViewerApp(void);
	virtual ~MotionViewerApp(void);

protected:
	virtual void createScene(void);
	virtual bool frameStarted(const FrameEvent& evt);
	virtual void setupEventHandlers(void);

	virtual bool processUnbufferedKeyInput(const FrameEvent& evt);

	virtual bool mouseMoved( const OIS::MouseEvent &arg );

	void addCharacter(char* filename);

	MocapVisualizer*	m_pVisualizer;
	ViconRTVisualizer*  m_pViconRTVisualizer;
	ViconVVisualizer*	m_pViconVVisualizer;
	ViconCharacter*		m_pCharacter1;
	ViconCharacter*		m_pCharacter2;

	// new data structure
	std::vector <ViconCharacter>	m_vCharacters;
	std::vector <ViconVisualizer*>	m_vViconVisualizers;
	std::vector< ViconCharacter >::iterator m_itrCharacter;
	std::vector< ViconVisualizer* >::iterator m_itrVisualizer;

	SceneNode*			pCameraController;
	SceneNode*			headNode;
	std::string			m_sDebugText;	

	// gui test
	bool handleLoad(const CEGUI::EventArgs& e);
	bool handleFileDialogOutput(const CEGUI::EventArgs& e);

	// actual GUI
	int			m_iCurrDataSetSelected;
	int			m_iCurrCharacterSelected;
	int			m_iMapLoaderDataSetSelected;
	int			m_iCurrDataSetColorItem;
	
	std::string m_sViconFile;
	std::string m_sSubjectFile;
	std::string m_sRTAddress;
	std::string m_sMapFile;

	// List boxes for data tracking
	CEGUI::Combobox*		m_pCharacterCombobox;
	CEGUI::Combobox*		m_pMotionCombobox;
	CEGUI::Combobox*		m_pMotionConnectionCombobox;
	
	// dataset color control
	CEGUI::Window*    m_pColorSample;
	CEGUI::Scrollbar* m_pRed;
	CEGUI::Scrollbar* m_pGreen;
	CEGUI::Scrollbar* m_pBlue;

	// GUI event handlers
	bool handleMenuRollUpChanged(const CEGUI::EventArgs& e);
	bool handleTextInputFocused(const CEGUI::EventArgs& e);
	bool handleTextInputExit(const CEGUI::EventArgs& e);
	bool handleWarningClose(const CEGUI::EventArgs& e);

	// MotionData Tab
	bool handleNewVFile(const CEGUI::EventArgs& e);
	bool handleNewRT(const CEGUI::EventArgs& e);
	bool handleDataSetSelection(const CEGUI::EventArgs& e);
	bool handleDataSetOffset(const CEGUI::EventArgs& e);
	bool handleDataSetSpeed(const CEGUI::EventArgs& e);
	bool handleColorItemSelected(const CEGUI::EventArgs& e);
	bool handleColorChanged(const CEGUI::EventArgs& e);

	// Character Tab
	bool handleNewCharacter(const CEGUI::EventArgs& e);
	bool handleSetMapping(const CEGUI::EventArgs& e);
	bool handleCharacterSelection(const CEGUI::EventArgs& e);
	bool handleCharacterOffset(const CEGUI::EventArgs& e);

	// v file loader gui
	bool handleVFileVSK(const CEGUI::EventArgs& e);
	bool handleVFileV(const CEGUI::EventArgs& e);
	bool handleVFileLoaderCancel(const CEGUI::EventArgs& e);
	bool handleVFileLoaderOK(const CEGUI::EventArgs& e);
	bool handleVFileClose(const CEGUI::EventArgs& e);

	// rt connector gui
	bool handleRTLoaderVSK(const CEGUI::EventArgs& e);
	bool handleRTLoaderCancel(const CEGUI::EventArgs& e);
	bool handleRTLoaderOK(const CEGUI::EventArgs& e);
	bool handleRTLoaderClose(const CEGUI::EventArgs& e);
	
	// map file loader gui
	bool handleMapLoaderDataSet(const CEGUI::EventArgs& e);
	bool handleMapLoaderMap(const CEGUI::EventArgs& e);
	bool handleMapLoaderCancel(const CEGUI::EventArgs& e);
	bool handleMapLoaderOK(const CEGUI::EventArgs& e);
	bool handleMapLoaderClose(const CEGUI::EventArgs& e);


	// update position of performers according to band configuration file
	virtual void updatePerformers() {}
	
};


#endif // #ifndef __ViconRT_test_h_
